package com.acxy.weixin.kit;

import com.acxy.weixin.enums.ApiError;
import com.alibaba.fastjson.JSON;

import java.util.Map;

/**
 * 微信接口返回API
 * @author MrShun
 * @version 1.0
 * @Date 2017-06-22
 */
public class ApiResult {

    //响应吗
    private int code;

    //数据对象
    private Map data;

    //中文提示消息
    private String msg;

    //英文提示
    private String tips;

    public ApiResult(String result) {
        Map map = JSON.parseObject(result, Map.class);
        Object errcode = map.get("errcode");
        if (errcode == null) {
            data = map;
        } else {
            int c = Integer.parseInt(String.valueOf(errcode));
            code = c;
            tips = ApiError.getMsg(c);
            msg = String.valueOf(map.get("errmsg"));
        }

    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public Map getData() {
        return data;
    }

    public void setData(Map data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getTips() {
        return tips;
    }

    public void setTips(String tips) {
        this.tips = tips;
    }
}